<script setup lang="ts">
defineProps<{
  // 接收数组, 遍历渲染选项
  options: {
    label: string
    value: string | number
  }[]
  // 接收性别数据, 用来高亮
  modelValue: string | number | undefined
}>()

const emit = defineEmits<{
  // 点击时, 将被点击的性别往外传
  (e: 'update:modelValue', gender: string | number): void
}>()
</script>

<template>
  <div class="cp-radio-btn">
    <a
      class="item"
      :class="{ active: item.value === modelValue }"
      href="javascript:;"
      v-for="item in options"
      :key="item.value"
      @click="emit('update:modelValue', item.value)"
    >
      {{ item.label }}
    </a>
  </div>
</template>

<style lang="scss" scoped>
.cp-radio-btn {
  display: flex;
  flex-wrap: wrap;
  .item {
    height: 32px;
    min-width: 60px;
    line-height: 30px;
    padding: 0 14px;
    text-align: center;
    border: 1px solid var(--cp-bg);
    background-color: var(--cp-bg);
    margin-right: 10px;
    box-sizing: border-box;
    color: var(--cp-text2);
    margin-bottom: 10px;
    border-radius: 4px;
    transition: all 0.3s;
    &.active {
      border-color: var(--cp-primary);
      background-color: var(--cp-plain);
    }
  }
}
</style>
